//
//  Utilities.m
//  吃货·上海
//
//  Created by lanou on 15/11/26.
//  Copyright © 2015年 濮亚军. All rights reserved.
//

#import "Utilities.h"

@implementation Utilities

CGAffineTransform aspectFit(CGRect innerRect, CGRect outerRect) {
    
    CGFloat scaleFactor = MIN(outerRect.size.width/innerRect.size.width, outerRect.size.height/innerRect.size.height);
    CGAffineTransform scale = CGAffineTransformMakeScale(scaleFactor, scaleFactor);
    
    CGRect scaledInnerRect = CGRectApplyAffineTransform(innerRect, scale);
    CGAffineTransform translation =
    CGAffineTransformMakeTranslation((outerRect.size.width - scaledInnerRect.size.width) / 2 - scaledInnerRect.origin.x,
                                     (outerRect.size.height - scaledInnerRect.size.height) / 2 - scaledInnerRect.origin.y);
    return CGAffineTransformConcat(scale, translation);
}


@end
